package easy;

public class _122_BestTimetoBuyandSellStockII {
    public int maxProfit(int[] prices) {
        int mProfit = 0;
        int maxPos = 0,minPos = 0;
        for(int i=0;i<prices.length-1;i++){
            if(prices[i]<=prices[i+1]){
                maxPos = i+1;
            }else{
                mProfit+=(prices[maxPos] - prices[minPos]);
                minPos = i+1;
                maxPos = i+1;
            }
        }
        if(maxPos>minPos){
            mProfit+=(prices[maxPos] - prices[minPos]);
        }
        return mProfit;
    }

    //更快的方案
    public int maxProfit1(int[] prices) {
        int profit=0;

        for(int i=1;i<prices.length;i++){
            if(prices[i]>prices[i-1]){
                profit+= prices[i]-prices[i-1];
            }
        }
        return profit;
    }
}
